package com.climaxi.core.ui;

import com.pcr.android.R;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Loading extends LinearLayout {

	AnimationDrawable lightsAnimation;
	ImageView image;

	public Loading(Context context, AttributeSet attrs) {
		super(context, attrs);

		String infService = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li;

		li = (LayoutInflater) getContext().getSystemService(infService);
		li.inflate(R.layout.loading, this, true);

		image = (ImageView) findViewById(R.id.imageView1);

		// LinearLayout.LayoutParams lp = new
		// LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
		// LinearLayout.LayoutParams.WRAP_CONTENT);
		// lp.setMargins((int)convertPixelsToDp(320,getContext()),
		// (int)convertPixelsToDp(622,getContext()), 0, 0);
		// image.setLayoutParams(lp);
		// image.getLayoutParams().width = 64;
		// image.getLayoutParams().height = 64;
		lightsAnimation = (AnimationDrawable) image.getDrawable();

		this.setVisibility(View.GONE);
	}

	public void stop() {
		lightsAnimation.stop();
		this.setVisibility(View.GONE);
	}

	public void start() {
		this.setVisibility(View.VISIBLE);
		image.post(new Runnable() {

			public void run() {
				lightsAnimation.start();
			}
		});
	}
}
